export default {
    props: {
        data: {
            type: [Array, Function],
            default() {
                return []
            },
            ignore: true
        },
        query: {
            type: [Object, Function],
            default() {
                return {}
            },
            ignore: true
        },
    },
    methods: {
        _ajaxQuery(params) {
            return new Promise((resolve, reject) => {
                if (this.data instanceof Array) {
                    resolve(this.data)
                } else if (this.data instanceof Function) {
                    params = this._queryParams(params || {})
                    this.data(params).then(response => {
                        resolve(response.data)
                    }).catch(error => {
                        console.log(error)
                        reject(error)
                    })
                }
            })
        },
        _queryParams(params) {
            if (this.query instanceof Function) {
                params = this.query(params) || params
            } else if (this.query instanceof Object) {
                params = Object.assign({}, this.query, params)
            }

            return params
        },
    }
}